package com.code.zjm;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

/**
 * Created by ZJM on 2017/4/20.
 */

public class SecondActivity extends AppCompatActivity {
    private Button btBack;
    private TextView tvHint;
    private int number;
    private Intent intent;
    private Bundle bundle;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_second);
        initData();
        initView();
        initListener();
    }

    public void initData() {
        intent = getIntent();
        bundle = intent.getExtras();
        number = bundle.getInt("number");
    }

    public void initView() {
        btBack = (Button) findViewById(R.id.bt_back);
        tvHint = (TextView) findViewById(R.id.tv_hint);
        tvHint.setText("You access this activity " + number + " times");
    }


    public void initListener() {
        btBack.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                number++;
                bundle.putInt("numberResult", number);
                setResult(1, intent.putExtras(bundle));
                finish();
            }
        });
    }
}
